// app.js
App({
  globalData: {
    userInfo: null,
    satoken: null,
    satoken2: null,
    //URL: 'http://localhost:33333/wall', //设置全局请求URL
    URL: 'https://wallapi.gxlmedu.com/wall', //设置全局请求URL
    //URL2: 'http://47.107.117.59:33336/wall'
  },
  
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    // 获取顶部导航栏高度
    this.getCustomHeaderHeight();
  },

  /**
  * 封装wx.request请求
  * method： 请求方式
  * url: 请求地址
  * data： 要传递的参数
  * contentType: 'application/json':'application/x-www-form-urlencoded'
  * callback： 请求成功回调函数
  * errFun： 请求失败回调函数
  **/
  wxapi2(method, url, data, contentType, callback, errFun) {
    wx.request({
      url: this.globalData.URL2 + url,
      method: method,
      data: data,
      header: {
        'content-type': contentType,
        'Accept': 'application/json',
        'satoken': this.globalData.satoken2
      },
      dataType: 'json',
      success: function (res) {
        callback(res.data);
      },
      fail: function (err) {
        errFun(err);
      }
    })
  },
  wxapi(method, url, data, contentType, callback, errFun) {
    wx.request({
      url: this.globalData.URL + url,
      method: method,
      data: data,
      header: {
        'content-type': contentType,
        'Accept': 'application/json',
        'satoken': this.globalData.satoken
      },
      dataType: 'json',
      success: function (res) {
        callback(res.data);
      },
      fail: function (err) {
        errFun(err);
      }
    })
  },

  getCustomHeaderHeight() {
    // 获取自定义顶部高度相关参数
    let capsuleObj = wx.getMenuButtonBoundingClientRect();
    // console.log("==胶囊信息==");
    // console.log(capsuleObj);

    wx.getSystemInfo({
        success: (res) => {
            var statusBarHeight = res.statusBarHeight; //顶部状态栏高度
            this.globalData.statusBarHeight = statusBarHeight;

            this.globalData.capsuleObj = capsuleObj;
            this.globalData.titleHeight = statusBarHeight + capsuleObj.height + (capsuleObj.top - statusBarHeight) * 2;
        },
        failure() {
        }
    })
  },
})
